package com.yx.cloud.fragment;

import android.animation.Animator;
import android.app.Dialog;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.iot.base.bean.Device;
import com.iot.base.service.req.RemoveDeviceParam;
import com.iot.product.sweeper.bean.CleanRecord;
import com.iot.sweeper.AppContext;
import com.iot.sweeper.param.CleanSettingParam;
import com.iot.sweeper.param.MultiMapSwitchParam;
import com.iot.sweeper.param.RemoveMultiMapList;
import com.yx.cloud.R;
import com.yx.cloud.activity.AlarmClockActivity;
import com.yx.cloud.activity.CleanRecordActivity;
import com.yx.cloud.activity.ConsumablesMaintainActivity;
import com.yx.cloud.activity.FirmwareUpgradeActivity;
import com.yx.cloud.activity.GyroFirmwareUpgradeActivity;
import com.yx.cloud.activity.MainBottomTabActivity;
import com.yx.cloud.activity.ProductGuideActivity;
import com.yx.cloud.activity.RemoteControlActivity;
import com.yx.cloud.activity.RobotSettingsActivity;
import com.yx.cloud.activity.SharEquipmentActivity;
import com.yx.cloud.base.BaseActivity;
import com.yx.cloud.bean.tmall.TmallUnbindDeviceParam;
import com.yx.cloud.constant.Constants;
import com.yx.cloud.databinding.RightMenuBinding;
import com.yx.cloud.product.ProductConfigConstants;
import com.yx.cloud.product.laser.inxni.INXNIConstant;
import com.yx.cloud.product.laser.yxcloud.X5_MAX;
import com.yx.cloud.utils.AliHttpRequest_Runnable;
import com.yx.cloud.utils.CommonConfirmDialog2;
import com.yx.cloud.utils.DisplayUtil;
import com.yx.cloud.utils.Intent_utils;
import com.yx.cloud.utils.LoadProgressDialog;
import com.yx.cloud.utils.RomUtils;
import com.yx.cloud.utils.SharedPreferencesList;
import com.yx.cloud.utils.SharedPrefsUtil;
import com.yx.cloud.utils.ThreadUtils;
import com.yx.cloud.utils.ToastUtil;
import com.iot.product.sweeper.bean.CleanSettings;
import com.iot.product.sweeper.bean.Robot;
import com.iot.common.utils.Event;

import java.util.ArrayList;
import java.util.List;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONObject;

public class MenuRightFragment extends BaseActivity implements View.OnClickListener {

    private final static String TAG = "MenuRightFragment";
    private LoadProgressDialog loadProgressDialog;
    private String deviceType;
    private RightMenuBinding binding;
    private AliHttpRequest_Runnable runnable;
    private CleanSettings settings;
    private int unbindDevice = 0;
    private String tmallDeviceId = "";
    private Robot robot;
    private JSONObject productConfig;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = RightMenuBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        if (!EventBus.getDefault().isRegistered(this)) {//加上判断
            EventBus.getDefault().register(this);
        }
        initData();
    }

    @Override
    protected void onStart() {
        super.onStart();
        robot = AppContext.get().getCurrentDevice();
        deviceType = robot.getProductId();
        if (X5_MAX.PID.equals(deviceType)) {
            tmallDeviceId = robot.getTmalDeviceId();
            Log.i(TAG, "tmallDeviceId ww-------- : " + tmallDeviceId);
        }
        Constants.DELETE_DEVICE_ID = robot.getDeviceId();
        AppContext.getProductService().getQuiteTimeSettings();//获取一下勿扰用来在预约界面显示提示
    }

    private void showLoadingDialog() {
        if (loadProgressDialog != null) {
            if (loadProgressDialog.isShowing()) {
                loadProgressDialog.dismiss();
            }
        }
        loadProgressDialog = new LoadProgressDialog(this, 6);
        loadProgressDialog.addAnimatorListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                Log.i(TAG, "动画执行完毕--------------------------------------------- : ");
                ToastUtil.showShort(MenuRightFragment.this, R.string.U_T_NetworkTimeout);
            }

            @Override
            public void onAnimationCancel(Animator animation) {
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
            }
        });
        loadProgressDialog.show();
    }

    private void initData() {
        //在线
        robot = AppContext.get().getCurrentDevice();
        productConfig = AppContext.getConfig();
        if (robot.isOnline()) {
            binding.llRightMenuRemoteControl.setVisibility(View.VISIBLE);
            binding.llRightMenuPositionRobot.setVisibility(View.VISIBLE);
            binding.llRightMenuAppointmentTime.setVisibility(View.VISIBLE);
            binding.llRightMenuRobotSetting.setVisibility(View.VISIBLE);
            // 根据产品分类显示集尘桶 拖布风干 耗材
//            DisplayUtil.show(binding.llRightMenuDustCollectingBarrel, productConfig.optBoolean(ProductConfigConstants.hasDustCollectingBarrel));
            DisplayUtil.show(binding.llRightMenuConsumablesMaintain, productConfig.optBoolean(ProductConfigConstants.hasConsumablesMaintain));
            //DisplayUtil.show(binding.llRightMenuMopDry, productConfig.optBoolean(ProductConfigConstants.hasMopDry));//拖布风干
            //DisplayUtil.show(binding.llRightMenuCleaningMopSettings, productConfig.optBoolean(ProductConfigConstants.cleaning_mop_settings));//清洗拖布设置
            //DisplayUtil.show(binding.llRightMenuCameraVideo, productConfig.optBoolean(ProductConfigConstants.hasCameraVideo));//摄像机视频
            if (productConfig.optBoolean(ProductConfigConstants.hasShare)) {
                //判断设备是否是共享（除X5机器外）
                boolean share = robot.isShare();
                if (!share) {
                    Robot device = AppContext.get().getCurrentDevice();
                    if (device != null) {
                        int update_state = device.getFirmwareUpdateInfo().getUpgradeStatus();
                        if (update_state == 1) {
                            binding.ivFirmwareUpgradeRead.setVisibility(View.VISIBLE);
                        } else {
                            binding.ivFirmwareUpgradeRead.setVisibility(View.INVISIBLE);
                        }
                    }
                }
                DisplayUtil.show(binding.llRightMenuSharEquipment, !share); //如果是自己的机器(非共享)就显示
                DisplayUtil.show(binding.llRightMenuFirmwareUpgrade, !share);
            } else {
                //X5直接就没有分享功能
                binding.llRightMenuSharEquipment.setVisibility(View.GONE);
            }

            DisplayUtil.show(binding.llRightMenuMultiMapSwitch, productConfig.optBoolean(ProductConfigConstants.robotSetting_multiMap));
            settings = robot.getCleanSettings();
            //多楼层地图
            binding.cbMultiMapSwitch.setChecked(settings.isOpenMultiMap());
            binding.cbMultiMapSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (!isChecked) {
                        CommonConfirmDialog2.newBuilder()
                                .context(MenuRightFragment.this)
                                .message(getString(R.string.MO_MultiMap_Close))
                                .confirmCallback(new CommonConfirmDialog2.ConfirmCallback() {
                                    @Override
                                    public boolean onConfirm() {
                                        //TODO
                                        MultiMapSwitchParam param = new MultiMapSwitchParam();
                                        param.setOpen(isChecked);
                                        AppContext.get().getCurrentDevice().multiMapSwitch(param);
                                        AppContext.getProductService().getMapList();
                                        return true;
                                    }

                                    @Override
                                    public boolean onCancel() {
                                        binding.cbMultiMapSwitch.setChecked(true);
                                        return true;
                                    }
                                }).build().show();
                    } else {
                        MultiMapSwitchParam param = new MultiMapSwitchParam();
                        param.setOpen(isChecked);
                        AppContext.get().getCurrentDevice().multiMapSwitch(param);
                    }
                }
            });
        } else {
            //离线
            binding.llRightMenuDustCollectingBarrel.setVisibility(View.GONE);
            binding.llRightMenuConsumablesMaintain.setVisibility(View.GONE);
//            binding.llRightMenuMopDry.setVisibility(View.GONE);
            binding.llRightMenuSharEquipment.setVisibility(View.GONE);
            binding.llRightMenuFirmwareUpgrade.setVisibility(View.GONE);
            binding.llRightMenuRemoteControl.setVisibility(View.GONE);
            binding.llRightMenuPositionRobot.setVisibility(View.GONE);
            binding.llRightMenuAppointmentTime.setVisibility(View.GONE);
            binding.llRightMenuRobotSetting.setVisibility(View.GONE);
            binding.cbMultiMapSwitch.setVisibility(View.GONE);
            // binding.llRightMenuCleaningMopSettings.setVisibility(View.GONE);
            //   binding.llRightMenuCameraVideo.setVisibility(View.GONE);

        }
        binding.llRightMenuCleanRecord.setVisibility(View.VISIBLE);
        binding.llRightMenuProductGuide.setVisibility(View.VISIBLE);
        binding.llRightMenuRemoveEquipment.setVisibility(View.VISIBLE);
        binding.llRightMenuAppointmentTime.setOnClickListener(this);
        binding.llRightMenuCleanRecord.setOnClickListener(this);
        binding.llRightMenuRemoteControl.setOnClickListener(this);
        binding.llRightMenuSharEquipment.setOnClickListener(this);
        binding.llRightMenuConsumablesMaintain.setOnClickListener(this);
        binding.llRightMenuProductGuide.setOnClickListener(this);
        binding.llRightMenuFirmwareUpgrade.setOnClickListener(this);
        binding.llRightMenuPositionRobot.setOnClickListener(this);
        binding.llRightMenuRemoveEquipment.setOnClickListener(this);
        binding.llRightMenuRobotSetting.setOnClickListener(this);

        binding.llRightMenuDustCollectingBarrel.setOnClickListener(this);
        binding.ivRightMenuReturn.setOnClickListener(this);
        //binding.llRightMenuMopDry.setOnClickListener(this);
        //binding.llRightMenuCleaningMopSettings.setOnClickListener(this);
//        binding.llLiveVideo.setOnClickListener(this);
//        binding.llCameraSettings.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (RomUtils.isFastClick()) {
            return;
        }
        switch (v.getId()) {
            case R.id.iv_rightMenuReturn:
                Intent_utils.backIntent(this);
                break;
            case R.id.ll_rightMenuAppointmentTime:
                //预约定时
                Intent_utils.enterIntent(this, AlarmClockActivity.class);
                break;
            case R.id.ll_rightMenuCleanRecord:
                //清扫记录
                Intent_utils.enterIntent(this, CleanRecordActivity.class);
                break;
            case R.id.ll_rightMenuRemoteControl:
                //遥控模式
                Intent_utils.enterIntent(this, RemoteControlActivity.class);
                break;
//            case R.id.ll_rightMenu_DustCollectingBarrel:
//                //集尘桶
//                Intent_utils.enterIntent(this, DustCollectingBarrelActivity.class);
//                break;
//            case R.id.ll_rightMenu_cleaningMopSettings:
//                //清洗拖布设置
//                Intent_utils.enterIntent(this, CleaningMopSettingsActivity.class);
//                break;
//            case R.id.ll_rightMenu_MopDry:
//                //拖布风干
////                Intent_utils.enterIntent(this, MopDryActivity.class);
//                int state = AppContext.get().getCurrentDevice().getRobotStatus().getWorkState();
//                if (RobotStatus.STATE_CHARGING != state) {
//                    mopDryDialog(getString(R.string.key26), getString(R.string.robot_not_home));
//                } else {
//                    airDryImmediatelyDialog(getString(R.string.mop_air_dry_immediately), getString(R.string.mop_air_dry_now));
//                }
//                break;
            case R.id.ll_rightMenuRobotSetting:
                //机器人设置
                Intent_utils.enterIntent(this, RobotSettingsActivity.class);
                break;
            case R.id.ll_rightMenuSharEquipment:
                //设备共享
                Intent_utils.enterIntent(this, SharEquipmentActivity.class);
                break;
            case R.id.ll_rightMenuConsumablesMaintain:
                //耗材与保养
                Intent_utils.enterIntent(this, ConsumablesMaintainActivity.class);
                break;
            case R.id.ll_rightMenuProductGuide:
                //产品指南
                Intent_utils.enterIntent(this, ProductGuideActivity.class);
                break;
            case R.id.ll_rightMenuFirmwareUpgrade:
                //固件升级
                if (productConfig.optBoolean(ProductConfigConstants.canUpgradeFirmwareChannel)) {
                    Intent_utils.enterIntentContext(this, GyroFirmwareUpgradeActivity.class, "type", "rigth");
                } else {
                    Intent_utils.enterIntentContext(this, FirmwareUpgradeActivity.class, "type", "rigth");
                }
                break;
            case R.id.ll_rightMenuPositionRobot:
                //机器人定位
                locateRobotDialog(getResources().getString(R.string.MO_FindRobot_Tip));
                break;
            case R.id.ll_rightMenuRemoveEquipment:
                //删除设备
                deleteEquipmentAndClearDataDialog();
                break;
//            case R.id.ll_liveVideo:
//                //实时视频
//                CameraSettings cameraSettings = AppContext.get().getCurrentDevice().getCameraSettings();
//                String password = cameraSettings.getGraphicPassword();
//                boolean isHomePrivacyPolicySwitch = SharedPrefsUtil.getValue(this, "VodeoPolicyState", "Vodeo_Polic", false);
//                if (!isHomePrivacyPolicySwitch) {
//                    CommonConfirmDialog2.newBuilder()
//                            .context(this)
//                            .btn1Name(getString(R.string.U_Cancel_Btn))
//                            .btn2Name(getString(R.string.L_Privacy_Btn_Agree))
//                            .message(getString(R.string.video_policy_not_open_tip))
//                            .confirmCallback(new CommonConfirmDialog2.ConfirmCallback() {
//                                @Override
//                                public boolean onConfirm() {
//                                    SharedPrefsUtil.putValue(MenuRightFragment.this, "VodeoPolicyState", "Vodeo_Polic", true);
//                                    return true;
//                                }
//
//                                @Override
//                                public boolean onCancel() {
//                                    return true;
//                                }
//                            }).build().show();
//                    return;
//                }
//                if (!cameraSettings.isLiveVideoSwitch()) {
//                    hintDialog(getString(R.string.video_not_open), getString(R.string.video_not_open_tip));
//                    return;
//                }
//
//                if (!TextUtils.isEmpty(password)) {
//                    Intent intent = new Intent(this, GraphicsPasswordActivity.class);
//                    intent.putExtra("tag", "verify");
//                    startActivity(intent);
//                    return;
//                }
//
//                Intent_utils.enterIntent(this, LiveVideoActivity.class);
//
//                break;
//            case R.id.ll_cameraSettings:
//                //摄像头设置
//                Intent_utils.enterIntent(this, CameraSettingsActivity.class);
//                break;
        }
    }

    private void hintDialog(String dialogTitle, String content) {
        Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.hint_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView mBtnCenteredConfirm = dialog.findViewById(R.id.btn_hintConfirm);
        TextView mTvDialogTitle = dialog.findViewById(R.id.tv_dialogHintTitle);
        TextView mTvDialogContent = dialog.findViewById(R.id.tv_hint_content);
        mTvDialogTitle.setText(dialogTitle);
        mTvDialogContent.setText(content);
        mBtnCenteredConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }


    private void mopDryDialog(String dialogTitle, String content) {
        Dialog dialog = new Dialog(MenuRightFragment.this);
        dialog.setContentView(R.layout.hint_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView tv_dialogHintTitle = dialog.findViewById(R.id.tv_dialogHintTitle);
        TextView tv_hint_content = dialog.findViewById(R.id.tv_hint_content);
        TextView mTvDialogTitle = dialog.findViewById(R.id.btn_hintConfirm);

        tv_dialogHintTitle.setVisibility(View.VISIBLE);
        tv_dialogHintTitle.setText(dialogTitle);
        tv_hint_content.setText(content);
        mTvDialogTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();

            }
        });
        dialog.show();
    }

    private void airDryImmediatelyDialog(String dialogTitle, String content) {
        Dialog dialog = new Dialog(MenuRightFragment.this);
        dialog.setContentView(R.layout.outlogin_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView tv_dialogTitle = dialog.findViewById(R.id.tv_dialogTitle);
        TextView tv_content = dialog.findViewById(R.id.tv_content);
        TextView btn_outLoginCancel = dialog.findViewById(R.id.btn_outLoginCancel);
        TextView btn_outLoginConfirm = dialog.findViewById(R.id.btn_outLoginConfirm);

        tv_dialogTitle.setVisibility(View.VISIBLE);
        tv_dialogTitle.setText(dialogTitle);
        tv_content.setText(content);
        btn_outLoginConfirm.setTextColor(getResources().getColor(R.color.button_color2));
        btn_outLoginCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        btn_outLoginConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppContext.getProductService().setDeviceCleanSettings(CleanSettingParam.newBuilder().dryState(true).build());
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    private void locateRobotDialog(String dialogTitle) {
        Dialog dialog = new Dialog(MenuRightFragment.this);
        dialog.setContentView(R.layout.content_centered_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.setCanceledOnTouchOutside(false);
        TextView mBtnOutLoginConfirm = dialog.findViewById(R.id.btn_centered_Confirm);
        TextView mBtnOutLoginCancel = dialog.findViewById(R.id.btn_centered_Cancel);
        TextView mTvDialogTitle = dialog.findViewById(R.id.tv_centered_dialogTitle);
        TextView mTvDialogContent = dialog.findViewById(R.id.tv_centered_dialogContent);
        mTvDialogTitle.setText(dialogTitle);
        mTvDialogContent.setVisibility(View.GONE);
        mBtnOutLoginConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //定位
                AppContext.getProductService().locateDevice();
                dialog.dismiss();
            }
        });
        mBtnOutLoginCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();

            }
        });
        dialog.show();
    }

    private void deleteEquipmentAndClearDataDialog() {
        Dialog dialog = new Dialog(MenuRightFragment.this);
        dialog.setContentView(R.layout.delete_device_dialog);
        dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        dialog.getWindow().setGravity(Gravity.BOTTOM);
        dialog.setCanceledOnTouchOutside(false);
        TextView mDeleteDevice = dialog.findViewById(R.id.tv_delete_device);
        TextView mDeleteDeviceAndClearData = dialog.findViewById(R.id.tv_delete_and_clear_data);
        mDeleteDeviceAndClearData.setText(R.string.MO_FactoryReset);
        JSONObject productConfig = AppContext.getConfig();
//        if (productConfig.optBoolean(ProductConfigConstants.isInxni)) {
//        } else {
//            mDeleteDeviceAndClearData.setText(R.string.morepage_robot_resetfactory);
//        }
        TextView mtvCancel = dialog.findViewById(R.id.tv_delete_device_cancel);

        mDeleteDevice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                //loadProgressDialog.show();
                //删除成功
//                AppContext.get().setDeviceVariety("default");
                showLoadingDialog();
                //删除
                Robot device = AppContext.get().getCurrentDevice();
                List<Device> removeDeviceList = new ArrayList<>();
                removeDeviceList.add(device);

                RemoveDeviceParam param = new RemoveDeviceParam();
                param.setDeviceList(removeDeviceList);
                AppContext.getProductService().removeDevice(param);
                dialog.dismiss();
            }
        });
        mDeleteDeviceAndClearData.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (RomUtils.isFastClick()) {
                    return;
                }
                Robot device = AppContext.get().getCurrentDevice();
                //删除成功
//                AppContext.get().setDeviceVariety("default");
                showLoadingDialog();
                //恢复出厂设置
                AppContext.getProductService().factoryReset();
                dialog.dismiss();
            }
        });
        mtvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.show();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(Event event) {
        switch (event.getType()) {
            case Event.MESSAGE_TYPE_DELETE_EQUIPMENT:
            case Event.MESSAGE_TYPE_RESTORE_FACTORY:
                if (event.isResult()) {
                    SharedPreferencesList.switchRobotPicture(this, "delete", "", AppContext.get().getDeviceList(), "delete");
                    if (X5_MAX.PID.equals(deviceType)) {
                        //扫地机删除成功后，再进行基站删除
                        SharedPreferencesList.switchRobotPictureX5(this, "delete", "", null, tmallDeviceId);
                        INXNIConstant.USER_OPEN_ID = SharedPrefsUtil.getValue(this, "TMALL_USER_OPEN_ID", "tmall_user_open_id", "");
                        TmallUnbindDeviceParam param = new TmallUnbindDeviceParam();
                        param.setUserOpenId(INXNIConstant.USER_OPEN_ID);
                        param.setDeviceId(tmallDeviceId);
                        if (runnable == null) {
                            runnable = new AliHttpRequest_Runnable();
                        }
                        runnable.initialization("unbind_device", param);
                    } else {
//                        ToastUtil.show(MenuRightFragment.this, getString(R.string.Robot_deleted), Toast.LENGTH_SHORT);
                        Intent_utils.backIntent(this, MainBottomTabActivity.class);
                    }
                } else {
                    ToastUtil.show(MenuRightFragment.this, getString(R.string.MM_T_Delete_No), Toast.LENGTH_SHORT);
                }

                break;
            case Event.MESSAGE_TYPE_UNBIND_DEVICE:
                //天猫设备解绑
                if (event.isResult()) {
                    loadProgressDialog.dismiss();
//                    ToastUtil.show(MenuRightFragment.this, getString(R.string.Robot_deleted), Toast.LENGTH_SHORT);
                    Intent_utils.backIntent(this);
                } else {
                    unbindDevice++;
                    if (unbindDevice <= 3) {
                        INXNIConstant.USER_OPEN_ID = SharedPrefsUtil.getValue(this, "TMALL_USER_OPEN_ID", "tmall_user_open_id", "");
                        TmallUnbindDeviceParam param = new TmallUnbindDeviceParam();
                        param.setUserOpenId(INXNIConstant.USER_OPEN_ID);
                        param.setDeviceId(tmallDeviceId);
                        if (runnable == null) {
                            runnable = new AliHttpRequest_Runnable();
                        }
                        runnable.initialization("unbind_device", param);
                    } else {
                        loadProgressDialog.dismiss();
                        unbindDevice = 0;
                        ToastUtil.show(MenuRightFragment.this, event.getContent().toString(), Toast.LENGTH_SHORT);
                        Intent_utils.backIntent(this);
                    }
                }
                break;
            case Event.MESSAGE_TYPE_GET_MULTI_MAP_LIST:
                ArrayList<CleanRecord> cleanRecords = (ArrayList<CleanRecord>) event.getContent();
                for (int i = 0; i < cleanRecords.size(); i++) {
                    if (cleanRecords.get(i).getId().equals(String.valueOf(AppContext.get().getCurrentDevice().getMap().getMap().mapId))) {
                        cleanRecords.remove(i);
                    }
                }

                ArrayList<String> fileNames = new ArrayList<>();
                for (CleanRecord cleanRecord : cleanRecords) {
                    fileNames.add(cleanRecord.getFileName());
                }

                RemoveMultiMapList removeMultiMapList = new RemoveMultiMapList();
                removeMultiMapList.setFileNames(fileNames);
                AppContext.getProductService().removeMultiMapList(removeMultiMapList);
                break;
        }
    }

    //    点击菜单返回按钮,程序退到后退运行
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent_utils.backIntent(this);
        }
        return super.onKeyDown(keyCode, event);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (runnable != null) {
            ThreadUtils.getInstance().removeThread(runnable);
        }
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this);
        }
        Log.i(TAG, "-onPause----------------------------");
    }
}
